# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
  include Minify::Cached

  def display_date(datetime, display_time = true)
    # 2009.04.05 14:23
    # datetime.strftime("%Y.%m.%d#{" %H:%M" if display_time}")
    
    # April 11, 2009 15:14
    datetime.to_s(:long)
  end
  
  def target_link(target)
    case target
      when BlogEntry
        blog_url(
          :year   => target.created_at.year,
          :month  => target.created_at.month,
          :day    => target.created_at.day,
          :title  => target.canonical_title
        )
      when Photo
        target.path
      else
        ""
    end
  end

  def default_text_field_tag(klass, attribute, instance = nil)
    text_field_tag(
      "#{klass}_#{attribute}", 
      instance ? instance.send(attribute) : attribute.humanize, 
      :class => "default #{klass}_#{attribute} #{"dormant" if !instance}",
      :autocomplete => "off")
  end
  
  def default_text_area_tag(klass, attribute, instance = nil)
    text_area_tag(
      "#{klass}_#{attribute}", 
      instance ? instance.send(attribute) : attribute.humanize, 
      :class => "default #{klass}_#{attribute} #{"dormant" if !instance}")
  end
  
end
